home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gdb.idb / usr / freeware / info / gdb.info-5.z / gdb.info-5
Encoding:
GNU Info File  |  1998-10-28  |  45.3 KB  |  1,174 lines

  1. This is Info file ./gdb.info, produced by Makeinfo version 1.68 from
  2. the input file gdb.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Gdb: (gdb).                     The GNU debugger.
  6. END-INFO-DIR-ENTRY
  7.    This file documents the GNU debugger GDB.
  8.  
  9.    This is the Fifth Edition, April 1998, of `Debugging with GDB: the
  10. GNU Source-Level Debugger' for GDB Version .
  11.  
  12.    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
  13. 1997, 1998 Free Software Foundation, Inc.
  14.  
  15.    Permission is granted to make and distribute verbatim copies of this
  16. manual provided the copyright notice and this permission notice are
  17. preserved on all copies.
  18.  
  19.    Permission is granted to copy and distribute modified versions of
  20. this manual under the conditions for verbatim copying, provided also
  21. that the entire resulting derived work is distributed under the terms
  22. of a permission notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions.
  27.  
  28. 
  29. File: gdb.info,  Node: M2 Operators,  Next: Built-In Func/Proc,  Up: Modula-2
  30.  
  31. Operators
  32. .........
  33.  
  34.    Operators must be defined on values of specific types.  For instance,
  35. `+' is defined on numbers, but not on structures.  Operators are often
  36. defined on groups of types.  For the purposes of Modula-2, the
  37. following definitions hold:
  38.  
  39.    * *Integral types* consist of `INTEGER', `CARDINAL', and their
  40.      subranges.
  41.  
  42.    * *Character types* consist of `CHAR' and its subranges.
  43.  
  44.    * *Floating-point types* consist of `REAL'.
  45.  
  46.    * *Pointer types* consist of anything declared as `POINTER TO TYPE'.
  47.  
  48.    * *Scalar types* consist of all of the above.
  49.  
  50.    * *Set types* consist of `SET' and `BITSET' types.
  51.  
  52.    * *Boolean types* consist of `BOOLEAN'.
  53.  
  54. The following operators are supported, and appear in order of
  55. increasing precedence:
  56.  
  57. `,'
  58.      Function argument or array index separator.
  59.  
  60. `:='
  61.      Assignment.  The value of VAR `:=' VALUE is VALUE.
  62.  
  63. `<, >'
  64.      Less than, greater than on integral, floating-point, or enumerated
  65.      types.
  66.  
  67. `<=, >='
  68.      Less than, greater than, less than or equal to, greater than or
  69.      equal to on integral, floating-point and enumerated types, or set
  70.      inclusion on set types.  Same precedence as `<'.
  71.  
  72. `=, <>, #'
  73.      Equality and two ways of expressing inequality, valid on scalar
  74.      types.  Same precedence as `<'.  In GDB scripts, only `<>' is
  75.      available for inequality, since `#' conflicts with the script
  76.      comment character.
  77.  
  78. `IN'
  79.      Set membership.  Defined on set types and the types of their
  80.      members.  Same precedence as `<'.
  81.  
  82. `OR'
  83.      Boolean disjunction.  Defined on boolean types.
  84.  
  85. `AND, &'
  86.      Boolean conjuction.  Defined on boolean types.
  87.  
  88. `@'
  89.      The GDB "artificial array" operator (*note Expressions:
  90.      Expressions.).
  91.  
  92. `+, -'
  93.      Addition and subtraction on integral and floating-point types, or
  94.      union and difference on set types.
  95.  
  96. `*'
  97.      Multiplication on integral and floating-point types, or set
  98.      intersection on set types.
  99.  
  100. `/'
  101.      Division on floating-point types, or symmetric set difference on
  102.      set types.  Same precedence as `*'.
  103.  
  104. `DIV, MOD'
  105.      Integer division and remainder.  Defined on integral types.  Same
  106.      precedence as `*'.
  107.  
  108. `-'
  109.      Negative. Defined on `INTEGER' and `REAL' data.
  110.  
  111. `^'
  112.      Pointer dereferencing.  Defined on pointer types.
  113.  
  114. `NOT'
  115.      Boolean negation.  Defined on boolean types.  Same precedence as
  116.      `^'.
  117.  
  118. `.'
  119.      `RECORD' field selector.  Defined on `RECORD' data.  Same
  120.      precedence as `^'.
  121.  
  122. `[]'
  123.      Array indexing.  Defined on `ARRAY' data.  Same precedence as `^'.
  124.  
  125. `()'
  126.      Procedure argument list.  Defined on `PROCEDURE' objects.  Same
  127.      precedence as `^'.
  128.  
  129. `::, .'
  130.      GDB and Modula-2 scope operators.
  131.  
  132.      *Warning:* Sets and their operations are not yet supported, so GDB
  133.      treats the use of the operator `IN', or the use of operators `+',
  134.      `-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an
  135.      error.
  136.  
  137. 
  138. File: gdb.info,  Node: Built-In Func/Proc,  Next: M2 Constants,  Prev: M2 Operators,  Up: Modula-2
  139.  
  140. Built-in functions and procedures
  141. .................................
  142.  
  143.    Modula-2 also makes available several built-in procedures and
  144. functions.  In describing these, the following metavariables are used:
  145.  
  146. A
  147.      represents an `ARRAY' variable.
  148.  
  149. C
  150.      represents a `CHAR' constant or variable.
  151.  
  152. I
  153.      represents a variable or constant of integral type.
  154.  
  155. M
  156.      represents an identifier that belongs to a set.  Generally used in
  157.      the same function with the metavariable S.  The type of S should
  158.      be `SET OF MTYPE' (where MTYPE is the type of M).
  159.  
  160. N
  161.      represents a variable or constant of integral or floating-point
  162.      type.
  163.  
  164. R
  165.      represents a variable or constant of floating-point type.
  166.  
  167. T
  168.      represents a type.
  169.  
  170. V
  171.      represents a variable.
  172.  
  173. X
  174.      represents a variable or constant of one of many types.  See the
  175.      explanation of the function for details.
  176.  
  177.    All Modula-2 built-in procedures also return a result, described
  178. below.
  179.  
  180. `ABS(N)'
  181.      Returns the absolute value of N.
  182.  
  183. `CAP(C)'
  184.      If C is a lower case letter, it returns its upper case equivalent,
  185.      otherwise it returns its argument
  186.  
  187. `CHR(I)'
  188.      Returns the character whose ordinal value is I.
  189.  
  190. `DEC(V)'
  191.      Decrements the value in the variable V.  Returns the new value.
  192.  
  193. `DEC(V,I)'
  194.      Decrements the value in the variable V by I.  Returns the new
  195.      value.
  196.  
  197. `EXCL(M,S)'
  198.      Removes the element M from the set S.  Returns the new set.
  199.  
  200. `FLOAT(I)'
  201.      Returns the floating point equivalent of the integer I.
  202.  
  203. `HIGH(A)'
  204.      Returns the index of the last member of A.
  205.  
  206. `INC(V)'
  207.      Increments the value in the variable V.  Returns the new value.
  208.  
  209. `INC(V,I)'
  210.      Increments the value in the variable V by I.  Returns the new
  211.      value.
  212.  
  213. `INCL(M,S)'
  214.      Adds the element M to the set S if it is not already there.
  215.      Returns the new set.
  216.  
  217. `MAX(T)'
  218.      Returns the maximum value of the type T.
  219.  
  220. `MIN(T)'
  221.      Returns the minimum value of the type T.
  222.  
  223. `ODD(I)'
  224.      Returns boolean TRUE if I is an odd number.
  225.  
  226. `ORD(X)'
  227.      Returns the ordinal value of its argument.  For example, the
  228.      ordinal value of a character is its ASCII value (on machines
  229.      supporting the ASCII character set).  X must be of an ordered
  230.      type, which include integral, character and enumerated types.
  231.  
  232. `SIZE(X)'
  233.      Returns the size of its argument.  X can be a variable or a type.
  234.  
  235. `TRUNC(R)'
  236.      Returns the integral part of R.
  237.  
  238. `VAL(T,I)'
  239.      Returns the member of the type T whose ordinal value is I.
  240.  
  241.      *Warning:*  Sets and their operations are not yet supported, so
  242.      GDB treats the use of procedures `INCL' and `EXCL' as an error.
  243.  
  244. 
  245. File: gdb.info,  Node: M2 Constants,  Next: M2 Defaults,  Prev: Built-In Func/Proc,  Up: Modula-2
  246.  
  247. Constants
  248. .........
  249.  
  250.    GDB allows you to express the constants of Modula-2 in the following
  251. ways:
  252.  
  253.    * Integer constants are simply a sequence of digits.  When used in an
  254.      expression, a constant is interpreted to be type-compatible with
  255.      the rest of the expression.  Hexadecimal integers are specified by
  256.      a trailing `H', and octal integers by a trailing `B'.
  257.  
  258.    * Floating point constants appear as a sequence of digits, followed
  259.      by a decimal point and another sequence of digits.  An optional
  260.      exponent can then be specified, in the form `E[+|-]NNN', where
  261.      `[+|-]NNN' is the desired exponent.  All of the digits of the
  262.      floating point constant must be valid decimal (base 10) digits.
  263.  
  264.    * Character constants consist of a single character enclosed by a
  265.      pair of like quotes, either single (`'') or double (`"').  They may
  266.      also be expressed by their ordinal value (their ASCII value,
  267.      usually) followed by a `C'.
  268.  
  269.    * String constants consist of a sequence of characters enclosed by a
  270.      pair of like quotes, either single (`'') or double (`"').  Escape
  271.      sequences in the style of C are also allowed.  *Note C and C++
  272.      constants: C Constants, for a brief explanation of escape
  273.      sequences.
  274.  
  275.    * Enumerated constants consist of an enumerated identifier.
  276.  
  277.    * Boolean constants consist of the identifiers `TRUE' and `FALSE'.
  278.  
  279.    * Pointer constants consist of integral values only.
  280.  
  281.    * Set constants are not yet supported.
  282.  
  283. 
  284. File: gdb.info,  Node: M2 Defaults,  Next: Deviations,  Prev: M2 Constants,  Up: Modula-2
  285.  
  286. Modula-2 defaults
  287. .................
  288.  
  289.    If type and range checking are set automatically by GDB, they both
  290. default to `on' whenever the working language changes to Modula-2.
  291. This happens regardless of whether you, or GDB, selected the working
  292. language.
  293.  
  294.    If you allow GDB to set the language automatically, then entering
  295. code compiled from a file whose name ends with `.mod' sets the working
  296. language to Modula-2. *Note Having GDB set the language automatically:
  297. Automatically, for further details.
  298.  
  299. 
  300. File: gdb.info,  Node: Deviations,  Next: M2 Checks,  Prev: M2 Defaults,  Up: Modula-2
  301.  
  302. Deviations from standard Modula-2
  303. .................................
  304.  
  305.    A few changes have been made to make Modula-2 programs easier to
  306. debug.  This is done primarily via loosening its type strictness:
  307.  
  308.    * Unlike in standard Modula-2, pointer constants can be formed by
  309.      integers.  This allows you to modify pointer variables during
  310.      debugging.  (In standard Modula-2, the actual address contained in
  311.      a pointer variable is hidden from you; it can only be modified
  312.      through direct assignment to another pointer variable or
  313.      expression that returned a pointer.)
  314.  
  315.    * C escape sequences can be used in strings and characters to
  316.      represent non-printable characters.  GDB prints out strings with
  317.      these escape sequences embedded.  Single non-printable characters
  318.      are printed using the `CHR(NNN)' format.
  319.  
  320.    * The assignment operator (`:=') returns the value of its right-hand
  321.      argument.
  322.  
  323.    * All built-in procedures both modify *and* return their argument.
  324.  
  325. 
  326. File: gdb.info,  Node: M2 Checks,  Next: M2 Scope,  Prev: Deviations,  Up: Modula-2
  327.  
  328. Modula-2 type and range checks
  329. ..............................
  330.  
  331.      *Warning:* in this release, GDB does not yet perform type or range
  332.      checking.
  333.  
  334.    GDB considers two Modula-2 variables type equivalent if:
  335.  
  336.    * They are of types that have been declared equivalent via a `TYPE
  337.      T1 = T2' statement
  338.  
  339.    * They have been declared on the same line.  (Note:  This is true of
  340.      the GNU Modula-2 compiler, but it may not be true of other
  341.      compilers.)
  342.  
  343.    As long as type checking is enabled, any attempt to combine variables
  344. whose types are not equivalent is an error.
  345.  
  346.    Range checking is done on all mathematical operations, assignment,
  347. array index bounds, and all built-in functions and procedures.
  348.  
  349. 
  350. File: gdb.info,  Node: M2 Scope,  Next: GDB/M2,  Prev: M2 Checks,  Up: Modula-2
  351.  
  352. The scope operators `::' and `.'
  353. ................................
  354.  
  355.    There are a few subtle differences between the Modula-2 scope
  356. operator (`.') and the GDB scope operator (`::').  The two have similar
  357. syntax:
  358.  
  359.  
  360.      MODULE . ID
  361.      SCOPE :: ID
  362.  
  363. where SCOPE is the name of a module or a procedure, MODULE the name of
  364. a module, and ID is any declared identifier within your program, except
  365. another module.
  366.  
  367.    Using the `::' operator makes GDB search the scope specified by
  368. SCOPE for the identifier ID.  If it is not found in the specified
  369. scope, then GDB searches all scopes enclosing the one specified by
  370. SCOPE.
  371.  
  372.    Using the `.' operator makes GDB search the current scope for the
  373. identifier specified by ID that was imported from the definition module
  374. specified by MODULE.  With this operator, it is an error if the
  375. identifier ID was not imported from definition module MODULE, or if ID
  376. is not an identifier in MODULE.
  377.  
  378. 
  379. File: gdb.info,  Node: GDB/M2,  Prev: M2 Scope,  Up: Modula-2
  380.  
  381. GDB and Modula-2
  382. ................
  383.  
  384.    Some GDB commands have little use when debugging Modula-2 programs.
  385. Five subcommands of `set print' and `show print' apply specifically to
  386. C and C++: `vtbl', `demangle', `asm-demangle', `object', and `union'.
  387. The first four apply to C++, and the last to the C `union' type, which
  388. has no direct analogue in Modula-2.
  389.  
  390.    The `@' operator (*note Expressions: Expressions.), while available
  391. while using any language, is not useful with Modula-2.  Its intent is
  392. to aid the debugging of "dynamic arrays", which cannot be created in
  393. Modula-2 as they can in C or C++.  However, because an address can be
  394. specified by an integral constant, the construct `{TYPE}ADREXP' is
  395. still useful.  (*note Expressions: Expressions.)
  396.  
  397.    In GDB scripts, the Modula-2 inequality operator `#' is interpreted
  398. as the beginning of a comment.  Use `<>' instead.
  399.  
  400. 
  401. File: gdb.info,  Node: Symbols,  Next: Altering,  Prev: Languages,  Up: Top
  402.  
  403. Examining the Symbol Table
  404. **************************
  405.  
  406.    The commands described in this section allow you to inquire about the
  407. symbols (names of variables, functions and types) defined in your
  408. program.  This information is inherent in the text of your program and
  409. does not change as your program executes.  GDB finds it in your
  410. program's symbol table, in the file indicated when you started GDB
  411. (*note Choosing files: File Options.), or by one of the file-management
  412. commands (*note Commands to specify files: Files.).
  413.  
  414.    Occasionally, you may need to refer to symbols that contain unusual
  415. characters, which GDB ordinarily treats as word delimiters.  The most
  416. frequent case is in referring to static variables in other source files
  417. (*note Program variables: Variables.).  File names are recorded in
  418. object files as debugging symbols, but GDB would ordinarily parse a
  419. typical file name, like `foo.c', as the three words `foo' `.' `c'.  To
  420. allow GDB to recognize `foo.c' as a single symbol, enclose it in single
  421. quotes; for example,
  422.  
  423.      p 'foo.c'::x
  424.  
  425. looks up the value of `x' in the scope of the file `foo.c'.
  426.  
  427. `info address SYMBOL'
  428.      Describe where the data for SYMBOL is stored.  For a register
  429.      variable, this says which register it is kept in.  For a
  430.      non-register local variable, this prints the stack-frame offset at
  431.      which the variable is always stored.
  432.  
  433.      Note the contrast with `print &SYMBOL', which does not work at all
  434.      for a register variable, and for a stack local variable prints the
  435.      exact address of the current instantiation of the variable.
  436.  
  437. `whatis EXP'
  438.      Print the data type of expression EXP.  EXP is not actually
  439.      evaluated, and any side-effecting operations (such as assignments
  440.      or function calls) inside it do not take place.  *Note
  441.      Expressions: Expressions.
  442.  
  443. `whatis'
  444.      Print the data type of `$', the last value in the value history.
  445.  
  446. `ptype TYPENAME'
  447.      Print a description of data type TYPENAME.  TYPENAME may be the
  448.      name of a type, or for C code it may have the form `class
  449.      CLASS-NAME', `struct STRUCT-TAG', `union UNION-TAG' or `enum
  450.      ENUM-TAG'.
  451.  
  452. `ptype EXP'
  453. `ptype'
  454.      Print a description of the type of expression EXP.  `ptype'
  455.      differs from `whatis' by printing a detailed description, instead
  456.      of just the name of the type.
  457.  
  458.      For example, for this variable declaration:
  459.  
  460.           struct complex {double real; double imag;} v;
  461.  
  462.      the two commands give this output:
  463.  
  464.           (gdb) whatis v
  465.           type = struct complex
  466.           (gdb) ptype v
  467.           type = struct complex {
  468.               double real;
  469.               double imag;
  470.           }
  471.  
  472.      As with `whatis', using `ptype' without an argument refers to the
  473.      type of `$', the last value in the value history.
  474.  
  475. `info types REGEXP'
  476. `info types'
  477.      Print a brief description of all types whose name matches REGEXP
  478.      (or all types in your program, if you supply no argument).  Each
  479.      complete typename is matched as though it were a complete line;
  480.      thus, `i type value' gives information on all types in your
  481.      program whose name includes the string `value', but `i type
  482.      ^value$' gives information only on types whose complete name is
  483.      `value'.
  484.  
  485.      This command differs from `ptype' in two ways: first, like
  486.      `whatis', it does not print a detailed description; second, it
  487.      lists all source files where a type is defined.
  488.  
  489. `info source'
  490.      Show the name of the current source file--that is, the source file
  491.      for the function containing the current point of execution--and
  492.      the language it was written in.
  493.  
  494. `info sources'
  495.      Print the names of all source files in your program for which
  496.      there is debugging information, organized into two lists: files
  497.      whose symbols have already been read, and files whose symbols will
  498.      be read when needed.
  499.  
  500. `info functions'
  501.      Print the names and data types of all defined functions.
  502.  
  503. `info functions REGEXP'
  504.      Print the names and data types of all defined functions whose
  505.      names contain a match for regular expression REGEXP.  Thus, `info
  506.      fun step' finds all functions whose names include `step'; `info
  507.      fun ^step' finds those whose names start with `step'.
  508.  
  509. `info variables'
  510.      Print the names and data types of all variables that are declared
  511.      outside of functions (i.e., excluding local variables).
  512.  
  513. `info variables REGEXP'
  514.      Print the names and data types of all variables (except for local
  515.      variables) whose names contain a match for regular expression
  516.      REGEXP.
  517.  
  518.      Some systems allow individual object files that make up your
  519.      program to be replaced without stopping and restarting your
  520.      program.  For example, in VxWorks you can simply recompile a
  521.      defective object file and keep on running.  If you are running on
  522.      one of these systems, you can allow GDB to reload the symbols for
  523.      automatically relinked modules:
  524.  
  525.     `set symbol-reloading on'
  526.           Replace symbol definitions for the corresponding source file
  527.           when an object file with a particular name is seen again.
  528.  
  529.     `set symbol-reloading off'
  530.           Do not replace symbol definitions when re-encountering object
  531.           files of the same name.  This is the default state; if you
  532.           are not running on a system that permits automatically
  533.           relinking modules, you should leave `symbol-reloading' off,
  534.           since otherwise GDB may discard symbols when linking large
  535.           programs, that may contain several modules (from different
  536.           directories or libraries) with the same name.
  537.  
  538.     `show symbol-reloading'
  539.           Show the current `on' or `off' setting.
  540.  
  541. `maint print symbols FILENAME'
  542. `maint print psymbols FILENAME'
  543. `maint print msymbols FILENAME'
  544.      Write a dump of debugging symbol data into the file FILENAME.
  545.      These commands are used to debug the GDB symbol-reading code.  Only
  546.      symbols with debugging data are included.  If you use `maint print
  547.      symbols', GDB includes all the symbols for which it has already
  548.      collected full details: that is, FILENAME reflects symbols for
  549.      only those files whose symbols GDB has read.  You can use the
  550.      command `info sources' to find out which files these are.  If you
  551.      use `maint print psymbols' instead, the dump shows information
  552.      about symbols that GDB only knows partially--that is, symbols
  553.      defined in files that GDB has skimmed, but not yet read
  554.      completely.  Finally, `maint print msymbols' dumps just the
  555.      minimal symbol information required for each object file from
  556.      which GDB has read some symbols.  *Note Commands to specify files:
  557.      Files, for a discussion of how GDB reads symbols (in the
  558.      description of `symbol-file').
  559.  
  560. 
  561. File: gdb.info,  Node: Altering,  Next: GDB Files,  Prev: Symbols,  Up: Top
  562.  
  563. Altering Execution
  564. ******************
  565.  
  566.    Once you think you have found an error in your program, you might
  567. want to find out for certain whether correcting the apparent error
  568. would lead to correct results in the rest of the run.  You can find the
  569. answer by experiment, using the GDB features for altering execution of
  570. the program.
  571.  
  572.    For example, you can store new values into variables or memory
  573. locations, give your program a signal, restart it at a different
  574. address, or even return prematurely from a function.
  575.  
  576. * Menu:
  577.  
  578. * Assignment::                  Assignment to variables
  579. * Jumping::                     Continuing at a different address
  580.  
  581. * Signaling::                   Giving your program a signal
  582.  
  583. * Returning::                   Returning from a function
  584. * Calling::                     Calling your program's functions
  585. * Patching::                    Patching your program
  586.  
  587. 
  588. File: gdb.info,  Node: Assignment,  Next: Jumping,  Up: Altering
  589.  
  590. Assignment to variables
  591. =======================
  592.  
  593.    To alter the value of a variable, evaluate an assignment expression.
  594. *Note Expressions: Expressions.  For example,
  595.  
  596.      print x=4
  597.  
  598. stores the value 4 into the variable `x', and then prints the value of
  599. the assignment expression (which is 4).  *Note Using GDB with Different
  600. Languages: Languages, for more information on operators in supported
  601. languages.
  602.  
  603.    If you are not interested in seeing the value of the assignment, use
  604. the `set' command instead of the `print' command.  `set' is really the
  605. same as `print' except that the expression's value is not printed and
  606. is not put in the value history (*note Value history: Value History.).
  607. The expression is evaluated only for its effects.
  608.  
  609.    If the beginning of the argument string of the `set' command appears
  610. identical to a `set' subcommand, use the `set variable' command instead
  611. of just `set'.  This command is identical to `set' except for its lack
  612. of subcommands.  For example, if your program has a variable `width',
  613. you get an error if you try to set a new value with just `set width=13',
  614. because GDB has the command `set width':
  615.  
  616.      (gdb) whatis width
  617.      type = double
  618.      (gdb) p width
  619.      $4 = 13
  620.      (gdb) set width=47
  621.      Invalid syntax in expression.
  622.  
  623. The invalid expression, of course, is `=47'.  In order to actually set
  624. the program's variable `width', use
  625.  
  626.      (gdb) set var width=47
  627.  
  628.    GDB allows more implicit conversions in assignments than C; you can
  629. freely store an integer value into a pointer variable or vice versa,
  630. and you can convert any structure to any other structure that is the
  631. same length or shorter.
  632.  
  633.    To store values into arbitrary places in memory, use the `{...}'
  634. construct to generate a value of specified type at a specified address
  635. (*note Expressions: Expressions.).  For example, `{int}0x83040' refers
  636. to memory location `0x83040' as an integer (which implies a certain size
  637. and representation in memory), and
  638.  
  639.      set {int}0x83040 = 4
  640.  
  641. stores the value 4 into that memory location.
  642.  
  643. 
  644. File: gdb.info,  Node: Jumping,  Next: Signaling,  Prev: Assignment,  Up: Altering
  645.  
  646. Continuing at a different address
  647. =================================
  648.  
  649.    Ordinarily, when you continue your program, you do so at the place
  650. where it stopped, with the `continue' command.  You can instead
  651. continue at an address of your own choosing, with the following
  652. commands:
  653.  
  654. `jump LINESPEC'
  655.      Resume execution at line LINESPEC.  Execution stops again
  656.      immediately if there is a breakpoint there.  *Note Printing source
  657.      lines: List, for a description of the different forms of LINESPEC.
  658.  
  659.      The `jump' command does not change the current stack frame, or the
  660.      stack pointer, or the contents of any memory location or any
  661.      register other than the program counter.  If line LINESPEC is in a
  662.      different function from the one currently executing, the results
  663.      may be bizarre if the two functions expect different patterns of
  664.      arguments or of local variables.  For this reason, the `jump'
  665.      command requests confirmation if the specified line is not in the
  666.      function currently executing.  However, even bizarre results are
  667.      predictable if you are well acquainted with the machine-language
  668.      code of your program.
  669.  
  670. `jump *ADDRESS'
  671.      Resume execution at the instruction at address ADDRESS.
  672.  
  673.    You can get much the same effect as the `jump' command by storing a
  674. new value into the register `$pc'.  The difference is that this does
  675. not start your program running; it only changes the address of where it
  676. *will* run when you continue.  For example,
  677.  
  678.      set $pc = 0x485
  679.  
  680. makes the next `continue' command or stepping command execute at
  681. address `0x485', rather than at the address where your program stopped.
  682. *Note Continuing and stepping: Continuing and Stepping.
  683.  
  684.    The most common occasion to use the `jump' command is to back up-
  685. perhaps with more breakpoints set-over a portion of a program that has
  686. already executed, in order to examine its execution in more detail.
  687.  
  688. 
  689. File: gdb.info,  Node: Signaling,  Next: Returning,  Prev: Jumping,  Up: Altering
  690.  
  691. Giving your program a signal
  692. ============================
  693.  
  694. `signal SIGNAL'
  695.      Resume execution where your program stopped, but immediately give
  696.      it the signal SIGNAL.  SIGNAL can be the name or the number of a
  697.      signal.  For example, on many systems `signal 2' and `signal
  698.      SIGINT' are both ways of sending an interrupt signal.
  699.  
  700.      Alternatively, if SIGNAL is zero, continue execution without
  701.      giving a signal.  This is useful when your program stopped on
  702.      account of a signal and would ordinary see the signal when resumed
  703.      with the `continue' command; `signal 0' causes it to resume
  704.      without a signal.
  705.  
  706.      `signal' does not repeat when you press <RET> a second time after
  707.      executing the command.
  708.  
  709.    Invoking the `signal' command is not the same as invoking the `kill'
  710. utility from the shell.  Sending a signal with `kill' causes GDB to
  711. decide what to do with the signal depending on the signal handling
  712. tables (*note Signals::.).  The `signal' command passes the signal
  713. directly to your program.
  714.  
  715. 
  716. File: gdb.info,  Node: Returning,  Next: Calling,  Prev: Signaling,  Up: Altering
  717.  
  718. Returning from a function
  719. =========================
  720.  
  721. `return'
  722. `return EXPRESSION'
  723.      You can cancel execution of a function call with the `return'
  724.      command.  If you give an EXPRESSION argument, its value is used as
  725.      the function's return value.
  726.  
  727.    When you use `return', GDB discards the selected stack frame (and
  728. all frames within it).  You can think of this as making the discarded
  729. frame return prematurely.  If you wish to specify a value to be
  730. returned, give that value as the argument to `return'.
  731.  
  732.    This pops the selected stack frame (*note Selecting a frame:
  733. Selection.), and any other frames inside of it, leaving its caller as
  734. the innermost remaining frame.  That frame becomes selected.  The
  735. specified value is stored in the registers used for returning values of
  736. functions.
  737.  
  738.    The `return' command does not resume execution; it leaves the
  739. program stopped in the state that would exist if the function had just
  740. returned.  In contrast, the `finish' command (*note Continuing and
  741. stepping: Continuing and Stepping.) resumes execution until the
  742. selected stack frame returns naturally.
  743.  
  744. 
  745. File: gdb.info,  Node: Calling,  Next: Patching,  Prev: Returning,  Up: Altering
  746.  
  747. Calling program functions
  748. =========================
  749.  
  750. `call EXPR'
  751.      Evaluate the expression EXPR without displaying `void' returned
  752.      values.
  753.  
  754.    You can use this variant of the `print' command if you want to
  755. execute a function from your program, but without cluttering the output
  756. with `void' returned values.  If the result is not void, it is printed
  757. and saved in the value history.
  758.  
  759.    A new user-controlled variable, CALL_SCRATCH_ADDRESS, specifies the
  760. location of a scratch area to be used when GDB calls a function in the
  761. target.  This is necessary because the usual method of putting the
  762. scratch area on the stack does not work in systems that have separate
  763. instruction and data spaces.
  764.  
  765. 
  766. File: gdb.info,  Node: Patching,  Prev: Calling,  Up: Altering
  767.  
  768. Patching programs
  769. =================
  770.  
  771.    By default, GDB opens the file containing your program's executable
  772. code (or the corefile) read-only.  This prevents accidental alterations
  773. to machine code; but it also prevents you from intentionally patching
  774. your program's binary.
  775.  
  776.    If you'd like to be able to patch the binary, you can specify that
  777. explicitly with the `set write' command.  For example, you might want
  778. to turn on internal debugging flags, or even to make emergency repairs.
  779.  
  780. `set write on'
  781. `set write off'
  782.      If you specify `set write on', GDB opens executable and core files
  783.      for both reading and writing; if you specify `set write off' (the
  784.      default), GDB opens them read-only.
  785.  
  786.      If you have already loaded a file, you must load it again (using
  787.      the `exec-file' or `core-file' command) after changing `set
  788.      write', for your new setting to take effect.
  789.  
  790. `show write'
  791.      Display whether executable files and core files are opened for
  792.      writing as well as reading.
  793.  
  794. 
  795. File: gdb.info,  Node: GDB Files,  Next: Targets,  Prev: Altering,  Up: Top
  796.  
  797. GDB Files
  798. *********
  799.  
  800.    GDB needs to know the file name of the program to be debugged, both
  801. in order to read its symbol table and in order to start your program.
  802. To debug a core dump of a previous run, you must also tell GDB the name
  803. of the core dump file.
  804.  
  805. * Menu:
  806.  
  807. * Files::                       Commands to specify files
  808. * Symbol Errors::               Errors reading symbol files
  809.  
  810. 
  811. File: gdb.info,  Node: Files,  Next: Symbol Errors,  Up: GDB Files
  812.  
  813. Commands to specify files
  814. =========================
  815.  
  816.    You may want to specify executable and core dump file names.  The
  817. usual way to do this is at start-up time, using the arguments to GDB's
  818. start-up commands (*note Getting In and Out of GDB: Invocation.).
  819.  
  820.    Occasionally it is necessary to change to a different file during a
  821. GDB session.  Or you may run GDB and forget to specify a file you want
  822. to use.  In these situations the GDB commands to specify new files are
  823. useful.
  824.  
  825. `file FILENAME'
  826.      Use FILENAME as the program to be debugged.  It is read for its
  827.      symbols and for the contents of pure memory.  It is also the
  828.      program executed when you use the `run' command.  If you do not
  829.      specify a directory and the file is not found in the GDB working
  830.      directory, GDB uses the environment variable `PATH' as a list of
  831.      directories to search, just as the shell does when looking for a
  832.      program to run.  You can change the value of this variable, for
  833.      both GDB and your program, using the `path' command.
  834.  
  835.      On systems with memory-mapped files, an auxiliary file
  836.      `FILENAME.syms' may hold symbol table information for FILENAME.
  837.      If so, GDB maps in the symbol table from `FILENAME.syms', starting
  838.      up more quickly.  See the descriptions of the file options
  839.      `-mapped' and `-readnow' (available on the command line, and with
  840.      the commands `file', `symbol-file', or `add-symbol-file',
  841.      described below), for more information.
  842.  
  843. `file'
  844.      `file' with no argument makes GDB discard any information it has
  845.      on both executable file and the symbol table.
  846.  
  847. `exec-file [ FILENAME ]'
  848.      Specify that the program to be run (but not the symbol table) is
  849.      found in FILENAME.  GDB searches the environment variable `PATH'
  850.      if necessary to locate your program.  Omitting FILENAME means to
  851.      discard information on the executable file.
  852.  
  853. `symbol-file [ FILENAME ]'
  854.      Read symbol table information from file FILENAME.  `PATH' is
  855.      searched when necessary.  Use the `file' command to get both symbol
  856.      table and program to run from the same file.
  857.  
  858.      `symbol-file' with no argument clears out GDB information on your
  859.      program's symbol table.
  860.  
  861.      The `symbol-file' command causes GDB to forget the contents of its
  862.      convenience variables, the value history, and all breakpoints and
  863.      auto-display expressions.  This is because they may contain
  864.      pointers to the internal data recording symbols and data types,
  865.      which are part of the old symbol table data being discarded inside
  866.      GDB.
  867.  
  868.      `symbol-file' does not repeat if you press <RET> again after
  869.      executing it once.
  870.  
  871.      When GDB is configured for a particular environment, it
  872.      understands debugging information in whatever format is the
  873.      standard generated for that environment; you may use either a GNU
  874.      compiler, or other compilers that adhere to the local conventions.
  875.      Best results are usually obtained from GNU compilers; for
  876.      example, using `gcc' you can generate debugging information for
  877.      optimized code.
  878.  
  879.      On some kinds of object files, the `symbol-file' command does not
  880.      normally read the symbol table in full right away.  Instead, it
  881.      scans the symbol table quickly to find which source files and
  882.      which symbols are present.  The details are read later, one source
  883.      file at a time, as they are needed.
  884.  
  885.      The purpose of this two-stage reading strategy is to make GDB
  886.      start up faster.  For the most part, it is invisible except for
  887.      occasional pauses while the symbol table details for a particular
  888.      source file are being read.  (The `set verbose' command can turn
  889.      these pauses into messages if desired.  *Note Optional warnings
  890.      and messages: Messages/Warnings.)
  891.  
  892.      We have not implemented the two-stage strategy for COFF yet.  When
  893.      the symbol table is stored in COFF format, `symbol-file' reads the
  894.      symbol table data in full right away.
  895.  
  896. `symbol-file FILENAME [ -readnow ] [ -mapped ]'
  897. `file FILENAME [ -readnow ] [ -mapped ]'
  898.      You can override the GDB two-stage strategy for reading symbol
  899.      tables by using the `-readnow' option with any of the commands that
  900.      load symbol table information, if you want to be sure GDB has the
  901.      entire symbol table available.
  902.  
  903.      If memory-mapped files are available on your system through the
  904.      `mmap' system call, you can use another option, `-mapped', to
  905.      cause GDB to write the symbols for your program into a reusable
  906.      file.  Future GDB debugging sessions map in symbol information
  907.      from this auxiliary symbol file (if the program has not changed),
  908.      rather than spending time reading the symbol table from the
  909.      executable program.  Using the `-mapped' option has the same
  910.      effect as starting GDB with the `-mapped' command-line option.
  911.  
  912.      You can use both options together, to make sure the auxiliary
  913.      symbol file has all the symbol information for your program.
  914.  
  915.      The auxiliary symbol file for a program called MYPROG is called
  916.      `MYPROG.syms'.  Once this file exists (so long as it is newer than
  917.      the corresponding executable), GDB always attempts to use it when
  918.      you debug MYPROG; no special options or commands are needed.
  919.  
  920.      The `.syms' file is specific to the host machine where you run
  921.      GDB.  It holds an exact image of the internal GDB symbol table.
  922.      It cannot be shared across multiple host platforms.
  923.  
  924. `core-file [ FILENAME ]'
  925.      Specify the whereabouts of a core dump file to be used as the
  926.      "contents of memory".  Traditionally, core files contain only some
  927.      parts of the address space of the process that generated them; GDB
  928.      can access the executable file itself for other parts.
  929.  
  930.      `core-file' with no argument specifies that no core file is to be
  931.      used.
  932.  
  933.      Note that the core file is ignored when your program is actually
  934.      running under GDB.  So, if you have been running your program and
  935.      you wish to debug a core file instead, you must kill the
  936.      subprocess in which the program is running.  To do this, use the
  937.      `kill' command (*note Killing the child process: Kill Process.).
  938.  
  939. `load FILENAME'
  940.      Depending on what remote debugging facilities are configured into
  941.      GDB, the `load' command may be available.  Where it exists, it is
  942.      meant to make FILENAME (an executable) available for debugging on
  943.      the remote system--by downloading, or dynamic linking, for example.
  944.      `load' also records the FILENAME symbol table in GDB, like the
  945.      `add-symbol-file' command.
  946.  
  947.      If your GDB does not have a `load' command, attempting to execute
  948.      it gets the error message "`You can't do that when your target is
  949.      ...'"
  950.  
  951.      The file is loaded at whatever address is specified in the
  952.      executable.  For some object file formats, you can specify the
  953.      load address when you link the program; for other formats, like
  954.      a.out, the object file format specifies a fixed address.
  955.  
  956.      On VxWorks, `load' links FILENAME dynamically on the current
  957.      target system as well as adding its symbols in GDB.
  958.  
  959.      With the Nindy interface to an Intel 960 board, `load' downloads
  960.      FILENAME to the 960 as well as adding its symbols in GDB.
  961.  
  962.      When you select remote debugging to a Hitachi SH, H8/300, or
  963.      H8/500 board (*note GDB and Hitachi Microprocessors: Hitachi
  964.      Remote.), the `load' command downloads your program to the Hitachi
  965.      board and also opens it as the current executable target for GDB
  966.      on your host (like the `file' command).
  967.  
  968.      `load' does not repeat if you press <RET> again after using it.
  969.  
  970. `add-symbol-file FILENAME ADDRESS'
  971. `add-symbol-file FILENAME ADDRESS [ -readnow ] [ -mapped ]'
  972.      The `add-symbol-file' command reads additional symbol table
  973.      information from the file FILENAME.  You would use this command
  974.      when FILENAME has been dynamically loaded (by some other means)
  975.      into the program that is running.  ADDRESS should be the memory
  976.      address at which the file has been loaded; GDB cannot figure this
  977.      out for itself.  You can specify ADDRESS as an expression.
  978.  
  979.      The symbol table of the file FILENAME is added to the symbol table
  980.      originally read with the `symbol-file' command.  You can use the
  981.      `add-symbol-file' command any number of times; the new symbol data
  982.      thus read keeps adding to the old.  To discard all old symbol data
  983.      instead, use the `symbol-file' command.
  984.  
  985.      `add-symbol-file' does not repeat if you press <RET> after using
  986.      it.
  987.  
  988.      You can use the `-mapped' and `-readnow' options just as with the
  989.      `symbol-file' command, to change how GDB manages the symbol table
  990.      information for FILENAME.
  991.  
  992. `add-shared-symbol-file'
  993.      The `add-shared-symbol-file' command can be used only under
  994.      Harris' CXUX operating system for the Motorola 88k.  GDB
  995.      automatically looks for shared libraries, however if GDB does not
  996.      find yours, you can run `add-shared-symbol-file'.  It takes no
  997.      arguments.
  998.  
  999. `section'
  1000.      The `section' command changes the base address of section SECTION
  1001.      of the exec file to ADDR.  This can be used if the exec file does
  1002.      not contain section addresses, (such as in the a.out format), or
  1003.      when the addresses specified in the file itself are wrong.  Each
  1004.      section must be changed separately.  The "info files" command
  1005.      lists all the sections and their addresses.
  1006.  
  1007. `info files'
  1008. `info target'
  1009.      `info files' and `info target' are synonymous; both print the
  1010.      current target (*note Specifying a Debugging Target: Targets.),
  1011.      including the names of the executable and core dump files
  1012.      currently in use by GDB, and the files from which symbols were
  1013.      loaded.  The command `help target' lists all possible targets
  1014.      rather than current ones.
  1015.  
  1016.    All file-specifying commands allow both absolute and relative file
  1017. names as arguments.  GDB always converts the file name to an absolute
  1018. file name and remembers it that way.
  1019.  
  1020.    GDB supports SunOS, SVr4, Irix 5, and IBM RS/6000 shared libraries.
  1021. GDB automatically loads symbol definitions from shared libraries when
  1022. you use the `run' command, or when you examine a core file.  (Before
  1023. you issue the `run' command, GDB does not understand references to a
  1024. function in a shared library, however--unless you are debugging a core
  1025. file).
  1026.  
  1027. `info share'
  1028. `info sharedlibrary'
  1029.      Print the names of the shared libraries which are currently loaded.
  1030.  
  1031. `sharedlibrary REGEX'
  1032. `share REGEX'
  1033.      Load shared object library symbols for files matching a Unix
  1034.      regular expression.  As with files loaded automatically, it only
  1035.      loads shared libraries required by your program for a core file or
  1036.      after typing `run'.  If REGEX is omitted all shared libraries
  1037.      required by your program are loaded.
  1038.  
  1039. 
  1040. File: gdb.info,  Node: Symbol Errors,  Prev: Files,  Up: GDB Files
  1041.  
  1042. Errors reading symbol files
  1043. ===========================
  1044.  
  1045.    While reading a symbol file, GDB occasionally encounters problems,
  1046. such as symbol types it does not recognize, or known bugs in compiler
  1047. output.  By default, GDB does not notify you of such problems, since
  1048. they are relatively common and primarily of interest to people
  1049. debugging compilers.  If you are interested in seeing information about
  1050. ill-constructed symbol tables, you can either ask GDB to print only one
  1051. message about each such type of problem, no matter how many times the
  1052. problem occurs; or you can ask GDB to print more messages, to see how
  1053. many times the problems occur, with the `set complaints' command (*note
  1054. Optional warnings and messages: Messages/Warnings.).
  1055.  
  1056.    The messages currently printed, and their meanings, include:
  1057.  
  1058. `inner block not inside outer block in SYMBOL'
  1059.      The symbol information shows where symbol scopes begin and end
  1060.      (such as at the start of a function or a block of statements).
  1061.      This error indicates that an inner scope block is not fully
  1062.      contained in its outer scope blocks.
  1063.  
  1064.      GDB circumvents the problem by treating the inner block as if it
  1065.      had the same scope as the outer block.  In the error message,
  1066.      SYMBOL may be shown as "`(don't know)'" if the outer block is not a
  1067.      function.
  1068.  
  1069. `block at ADDRESS out of order'
  1070.      The symbol information for symbol scope blocks should occur in
  1071.      order of increasing addresses.  This error indicates that it does
  1072.      not do so.
  1073.  
  1074.      GDB does not circumvent this problem, and has trouble locating
  1075.      symbols in the source file whose symbols it is reading.  (You can
  1076.      often determine what source file is affected by specifying `set
  1077.      verbose on'.  *Note Optional warnings and messages:
  1078.      Messages/Warnings.)
  1079.  
  1080. `bad block start address patched'
  1081.      The symbol information for a symbol scope block has a start address
  1082.      smaller than the address of the preceding source line.  This is
  1083.      known to occur in the SunOS 4.1.1 (and earlier) C compiler.
  1084.  
  1085.      GDB circumvents the problem by treating the symbol scope block as
  1086.      starting on the previous source line.
  1087.  
  1088. `bad string table offset in symbol N'
  1089.      Symbol number N contains a pointer into the string table which is
  1090.      larger than the size of the string table.
  1091.  
  1092.      GDB circumvents the problem by considering the symbol to have the
  1093.      name `foo', which may cause other problems if many symbols end up
  1094.      with this name.
  1095.  
  1096. `unknown symbol type `0xNN''
  1097.      The symbol information contains new data types that GDB does not
  1098.      yet know how to read.  `0xNN' is the symbol type of the
  1099.      misunderstood information, in hexadecimal.
  1100.  
  1101.      GDB circumvents the error by ignoring this symbol information.
  1102.      This usually allows you to debug your program, though certain
  1103.      symbols are not accessible.  If you encounter such a problem and
  1104.      feel like debugging it, you can debug `gdb' with itself,
  1105.      breakpoint on `complain', then go up to the function
  1106.      `read_dbx_symtab' and examine `*bufp' to see the symbol.
  1107.  
  1108. `stub type has NULL name'
  1109.      GDB could not find the full definition for a struct or class.
  1110.  
  1111. `const/volatile indicator missing (ok if using g++ v1.x), got...'
  1112.      The symbol information for a C++ member function is missing some
  1113.      information that recent versions of the compiler should have output
  1114.      for it.
  1115.  
  1116. `info mismatch between compiler and debugger'
  1117.      GDB could not parse a type specification output by the compiler.
  1118.  
  1119. 
  1120. File: gdb.info,  Node: Targets,  Next: Controlling GDB,  Prev: GDB Files,  Up: Top
  1121.  
  1122. Specifying a Debugging Target
  1123. *****************************
  1124.  
  1125.    A "target" is the execution environment occupied by your program.
  1126. Often, GDB runs in the same host environment as your program; in that
  1127. case, the debugging target is specified as a side effect when you use
  1128. the `file' or `core' commands.  When you need more flexibility--for
  1129. example, running GDB on a physically separate host, or controlling a
  1130. standalone system over a serial port or a realtime system over a TCP/IP
  1131. connection--you can use the `target' command to specify one of the
  1132. target types configured for GDB (*note Commands for managing targets:
  1133. Target Commands.).
  1134.  
  1135. * Menu:
  1136.  
  1137. * Active Targets::              Active targets
  1138. * Target Commands::             Commands for managing targets
  1139. * Remote::                      Remote debugging
  1140.  
  1141. 
  1142. File: gdb.info,  Node: Active Targets,  Next: Target Commands,  Up: Targets
  1143.  
  1144. Active targets
  1145. ==============
  1146.  
  1147.    There are three classes of targets: processes, core files, and
  1148. executable files.  GDB can work concurrently on up to three active
  1149. targets, one in each class.  This allows you to (for example) start a
  1150. process and inspect its activity without abandoning your work on a core
  1151. file.
  1152.  
  1153.    For example, if you execute `gdb a.out', then the executable file
  1154. `a.out' is the only active target.  If you designate a core file as
  1155. well--presumably from a prior run that crashed and coredumped--then GDB
  1156. has two active targets and uses them in tandem, looking first in the
  1157. corefile target, then in the executable file, to satisfy requests for
  1158. memory addresses.  (Typically, these two classes of target are
  1159. complementary, since core files contain only a program's read-write
  1160. memory--variables and so on--plus machine status, while executable
  1161. files contain only the program text and initialized data.)
  1162.  
  1163.    When you type `run', your executable file becomes an active process
  1164. target as well.  When a process target is active, all GDB commands
  1165. requesting memory addresses refer to that target; addresses in an
  1166. active core file or executable file target are obscured while the
  1167. process target is active.
  1168.  
  1169.    Use the `core-file' and `exec-file' commands to select a new core
  1170. file or executable target (*note Commands to specify files: Files.).
  1171. To specify as a target a process that is already running, use the
  1172. `attach' command (*note Debugging an already-running process: Attach.).
  1173.  
  1174.